
//
//  YTOAuthViewController.swift
//  Rhythm_SinaWeibo
//
//  Created by Mr.Rhythm on 9/26/15.
//  Copyright © 2015 Mr.Rhythm. All rights reserved.
//

import UIKit

class YTOAuthViewController: UIViewController {
    
    // 懒加载一个webView
    private lazy var webView = UIWebView()
    
    override func loadView() {
        
        view = webView
        
        title = "翻滚吧，肿瘤君"
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "关闭", style: .Plain, target: self, action: "close")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "自动填充", style: .Plain, target: self, action: "autoFill")
    }
    
    @objc private func close() {
        dismissViewControllerAnimated(true, completion: nil)
    }
    
    @objc private func autoFill() {
        let js = "document.getElementById('userId').value = 'thank1992you@sina.com';" +
        "document.getElementById('passwd').value = 'li6312024';"
        
        // 执行 js
        webView.stringByEvaluatingJavaScriptFromString(js)
    }
    
    override func viewDidLoad() {
        webView.loadRequest(NSURLRequest(URL: YTNetworkingTools.sharedTools.oauthURL))
    }
    
}
